/*
 * Powered By free
 * Web Site: 
 * Since 2018 - 2021
 */

package com.menhai.personmanagement.controller;

import java.text.SimpleDateFormat;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.menhai.personmanagement.entity.MbCommonRecord;
import com.menhai.personmanagement.services.MbCommonRecordService;
import com.menhai.personmanagement.services.MbIndexInputService;
import com.menhai.personmanagement.utils.UuidUtil;

@RestController
@RequestMapping("/mbCommonRecord")
public class MbCommonRecordController {
	
	 @Autowired
     private MbCommonRecordService mbCommonRecordService;
	 
	 @Autowired
     private MbIndexInputService mbIndexInputService;
     
     @RequestMapping("/add")
     public Object add(MbCommonRecord mbCommonRecord) throws Exception{
    	 SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    	 Map<String, Object> map = null;
    	 mbCommonRecord.setCommonRecordId(UuidUtil.uuid());
    	//取到患者所属医院
 	   	List<Map<String,Object>> list=mbIndexInputService.getOneByPopulation(mbCommonRecord.getPersonNo());
 	   	if(list!=null&&list.size()>0){
 	   		String hosnum=list.get(0).get("hosnum")+"";
 	   		mbCommonRecord.setHosnum(hosnum);
 	   	}
		map = mbCommonRecordService.add(mbCommonRecord);
		return map;
     }


     
 	@RequestMapping(value = "/edit", method = RequestMethod.POST)
 	public Object edit(HttpServletRequest request, HttpServletResponse response, MbCommonRecord mbCommonRecord) throws Exception {
 		SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
 		Map<String, Object> map = null;
 		//取到患者所属医院
 	   	List<Map<String,Object>> list=mbIndexInputService.getOneByPopulation(mbCommonRecord.getPersonNo());
 	   	if(list!=null&&list.size()>0){
 	   		String hosnum=list.get(0).get("hosnum")+"";
 	   		mbCommonRecord.setHosnum(hosnum);
 	   	}
		map = mbCommonRecordService.edit(mbCommonRecord);
 		return map;
 	}
 	
 	@RequestMapping("/delete")
    public Object delete(MbCommonRecord mbCommonRecord) throws Exception{
	   	 SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	   	 Map<String, Object> map = null;
	   	 String commonRecordId=mbCommonRecord.getCommonRecordId();
		 map = mbCommonRecordService.deleteById(commonRecordId);
		 return map;
    }
 	
 	@RequestMapping(value = "/getListByCondition", method = RequestMethod.POST)
 	public Object getListByCondition(HttpServletRequest request, HttpServletResponse response, MbCommonRecord mbCommonRecord) throws Exception {
 		List<Map<String,Object>> list = null;
 		list = mbCommonRecordService.getListByCondition(mbCommonRecord);
 		return list;
 	}
 	
 	@RequestMapping(value = "/getListByConditionByPage", method = RequestMethod.POST)
 	public Object getListByConditionByPage(HttpServletRequest request, HttpServletResponse response, MbCommonRecord mbCommonRecord) throws Exception {
 		IPage<MbCommonRecord> list = mbCommonRecordService.getListByConditionByPage(mbCommonRecord);
 		return list;
 	}
 	
 	@RequestMapping(value = "/getOneById", method = RequestMethod.POST)
 	public Object getOneById(HttpServletRequest request, HttpServletResponse response, MbCommonRecord mbCommonRecord) throws Exception {
 		List<Map<String,Object>> list = null;
 		list = mbCommonRecordService.getOneById(mbCommonRecord);
 		if(list.size()>0){
 			return list.get(0);
 		}
 		return list;
 	}
	
	
	
}